package org.toolbook.validator;

import com.jfinal.core.Controller;
import com.jfinal.validate.Validator;
/**
 * 修改日记的验证器
 * @author meigang
 * @date 2015-07-02 15:27
 *
 */
public class UpdateDiaryValidator extends Validator{

	@Override
	protected void validate(Controller c) {
		validateString("title", 1, 24, "title_info", "日记名长度[1-24]");
		validateString("note", 1, 120, "note_info", "日记摘要长度[1-120]");
		validateString("weather", 1, 40, "weather_info", "日记天气长度[1-40]");
		validateRequired("content", "content_info", "日记内容不能为空");
		
		String filePath = c.getPara("lookPhotoFilePath");
		if(filePath == null || filePath.equals("")){
			addError("lookPhotoFilePath_info", "缩览图未上传");
		}
	}

	@Override
	protected void handleError(Controller c) {
		// TODO Auto-generated method stub
		c.keepPara("title");
		c.keepPara("note");
		c.keepPara("content");
		c.keepPara("weather");
		c.keepPara("lookPhotoFilePath");
		c.render("/WEB-INF/pages/fc/diary/update.jsp");
	}

}
